<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c"%>
<%@ taglib uri="http://www.longtop.com/intelliweb" prefix="e"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>Insert title here</title>
	</head>
	<e:View id="view">
	    <script type="text/javascript">SkinUtil.getSkin();</script>
	    <script type="text/javascript">SkinUtil.getModuleSkin();</script>
	    
		<div id="Invisual Controls" style="min-height: 40px; background-color: LemonChiffon;" >
			<e:Dataset id="Dataset_AuthOper" datasetDefinition="DatasetDefinition_sys.dsd"
					datasetRef="dataset_authOper" pageSize="-1">
				<e:Field name="menuOrFuncId" dataType="string" label="权限代码" maxLength="" />
				<e:Field name="parentmenuOrFuncId" dataType="string" label="上级权限代码" maxLength="" />
				<e:Field name="operName" dataType="string" label="权限名称" maxLength="" />
				<e:Field name="authType" dataType="string" label="权限类型" maxLength="" />
				<e:Field name="hasChecked" dataType="string" label="是否有权限" maxLength="" />
			</e:Dataset> 
		
			<e:Command id="Command_SaveAuthOper"
				action="com.longtop.framework.sys.role.web.RoleAuthAction"
				method="saveRoleAuthOper" showHintInfoOnSuccess="false" onExecuteSuccess="Command_SaveAuthOper_onExecuteSuccess(command)">
				<e:Parameter name="roleId"></e:Parameter>
				<e:DatasetInfo name="DatasetInfo1" dataset="Dataset_AuthOper" submitType="all"></e:DatasetInfo>
			</e:Command> 
			
			<e:Dataset id="Dataset_AuthData" datasetDefinition="DatasetDefinition_sys.dsd"	datasetRef="dataset_authData" pageSize="-1">
				<e:Field name="id" dataType="string" label="id" maxLength="32" />
				<e:Field name="roleId" dataType="string" label="roleId" maxLength="32" />
				<e:Field name="tableName" dataType="string" label="tableName" maxLength="32" />
				<e:Field name="authType" dataType="string" label="authType" maxLength="1" />
				<e:Field name="authScopeId" dataType="string" label="authScopeId" maxLength="32" />
				<e:Field name="authScopeName" dataType="string" label="authScopeName" maxLength="100" />
				<e:Field name="isIncludeSubOrg" dataType="string" label="isIncludeSubOrg" maxLength="1" />
			</e:Dataset> 
		
			<e:Command id="Command_SaveAuthData" action="com.longtop.framework.sys.role.web.RoleAuthAction"	method="saveRoleAuthData" 
					validateRequired="true" showHintInfoOnSuccess="false" onExecuteSuccess="Command_SaveAuthData_onExecuteSuccess(command)">
				<e:DatasetInfo name="DatasetInfo2" dataset="Dataset_AuthData" alwayRefreshClient="true" submitType="changes"></e:DatasetInfo>
			</e:Command>
			
			<e:ListDropDown id="ListDropDown_TableName__1001" autoDropDown="false" fixed="true" onSelect="DataDropDown_Bizobj_onSelect(dropdown,record,text)">
				<!-- 由后台加载 -->
			</e:ListDropDown>
			
			<e:ListDropDown id="ListDropDown_authType" autoDropDown="true" fixed="true" onSelect="ListDropDown_authType_onSelect(dropdown,item,text)">
				<e:ListDropDownItem name="ListDropDownItem1" label="部门数据" value="1" selected="true"></e:ListDropDownItem>
				<!-- e:ListDropDownItem name="ListDropDownItem2" label="用户数据" value="2" -->		 
			</e:ListDropDown> 
			
			<e:ListDropDown id="ListDropDown_isIncludeSubOrg" autoDropDown="true" fixed="true">
				<e:ListDropDownItem name="ListDropDownItem3" label="否" value="0"></e:ListDropDownItem>
				<e:ListDropDownItem name="ListDropDownItem4" label="是" value="1"></e:ListDropDownItem>
			</e:ListDropDown> 
			
			<e:LookupDropDown id="LookupDropDown_DataScope"	path="/jsp/framework/sys/org/orgDropdown.jsp?from=dataAuth" windowWidth="650"
				windowHeight="500" fixed="true" autoDropDown="true"	onSelect="LookupDropDown_DataScope_onSelect(dropdown,iframe,text)"
				windowCaption="选择部门数据" onBeforeOpen="LookupDropDown_DataScope_onBeforeOpen(dropdown)">
			</e:LookupDropDown>  
		</div>
	
		<body>
			<e:Page id="ePage" action="com.longtop.framework.sys.role.web.RoleAuthAction" style="min-height: 80px; width: 100%; height: 100%;" onAfterLoadPage="ePage_onAfterLoadPage()">
				<table style="width: 100%; height: 100%;" border="0" cellpadding="0" cellspacing="0" width="100%" align="center">
					<tbody>
						<tr>
							<td align="left" valign="top">
								<e:Panel id="Panel1" style="width: 285px; height: 100%" caption="" captionIcon="/images/query_win.gif" captionStyle="color:#888888" allowFold="true" showArrowButton="false">
									<table style="text-align: left; width: 100%;" border="0" cellpadding="3" cellspacing="3" width="100%" align="center">
										<tbody>
											<tr>
												<td align="center">
													<e:Button id="Button_SelectAll" style="height: 22px; width: 70px" caption="全(不)选" onClick="Button_SelectAll_onClick()"></e:Button>&nbsp;&nbsp;
													<e:Button id="Button_Save" style="height: 22px; width: 70px" caption="保存" onClick="Button_Save_onClick()" icon="/images/submit.gif" ></e:Button>&nbsp;&nbsp;
													<e:Button id="Button_Return" style="height: 22px; width: 70px" caption="返回" onClick="Button_Return_onClick()" icon="/images/undo.gif" ></e:Button>
												</td>
											</tr>
											<tr>
												<td colspan="4" height="100%" width="100%" align="center" valign="top">
													<e:DataTree id="DataTree_Auth" dataset="Dataset_AuthOper" nameField="menuOrFuncId"
															parentField="parentmenuOrFuncId" labelField="operName" valueField="menuOrFuncId" checkedField="hasChecked"
															style="width: 100%; height: 390px; text-align: left;border-color:#3ABCFA"
															useDefaultFolderIcon="true" useCheckBox="true"
															checkedRelaNode="true" contextMenuItems="expand,collapse" lazyLoading="false">
													</e:DataTree>
												</td>
											</tr>
										</tbody>
									</table>
								</e:Panel>
							</td>
							<td valign="top" width="100%">
								<e:Panel id="Panel2" style="width: 100%; height: 100%" captionStyle="color:#888888" caption="角色名称:" captionIcon="/images/list_win.gif">
									<table style="text-align: left; width: 100%;" border="0" cellpadding="3" cellspacing="3" >
										<tbody>
											<tr>
												<td align="left">
													<e:RecordNavigator id="RecordNavigator_AuthData" dataset="Dataset_AuthData"	style="width: 0px" showNavigatorButton="false">
														<e:RecordButton id="RecordButton_insert" label="新增" onClick="RecordButton_insert_onClick()" icon="/images/add.gif"></e:RecordButton>
														<e:RecordButton id="RecordButton_delete" label="删除" onClick="deleteRecord" icon="/images/delete.gif"></e:RecordButton>
														<e:RecordButton id="RecordButton_Save" label="保存" icon="/images/submit.gif" command="Command_SaveAuthData"></e:RecordButton>
													</e:RecordNavigator>
												</td>
											</tr>
											<tr>
												<td height="100%" width="100%" align="left"	valign="top">
													<e:Grid id="Grid_AuthData" dataset="Dataset_AuthData" onClick="Grid_AuthData_onClick()" style="width: 100%; height: 380px;">
														<e:Column name="tableName" label="业务对象" field="tableName"	dataType="string" style="width:30%"	dropDown="ListDropDown_TableName__1001"></e:Column>
														<e:Column name="authType" label="数据类型" field="authType" dataType="string" style="width:15%" dropDown="ListDropDown_authType"></e:Column>
														<e:Column name="authScopeName" label="数据范围" field="authScopeName"	dataType="string" style="width:40%" readOnly="false" dropDown="LookupDropDown_DataScope"></e:Column>
														<e:Column name="isIncludeSubOrg" label="含下级部门" field="isIncludeSubOrg" dataType="string" style="width:15%"	dropDown="ListDropDown_isIncludeSubOrg"></e:Column>
													</e:Grid>
												</td>
											</tr>
										</tbody>
									</table>
								</e:Panel>
							</td>
						</tr>
					</tbody>
			    </table>
			</e:Page>
		</body>
	
		<script type="text/javascript">
		
			var flag = true;	//全(反)选标志
				
			//init
			function ePage_onAfterLoadPage(){
				//Button_Search_onClick();
			}
			
			//全(不)选
			function Button_SelectAll_onClick(){
				var tree = $J(DataTree_Auth);
				if(tree){
					if(flag) {
				    	tree.selectAll();
				    	flag = false;
				    } else {
				    	tree.unselectAll();
				    	flag = true;
				    }
				}
			}
			
			//保存功能权限
			function Button_Save_onClick(){
			    //把SubWindow_RoleAuth的tag里的信息放到command的parameter传上来
			    var panel = $J(Panel1);
			    var roleId = panel.tag;
			    var parameter = Command_SaveAuthOper.parameters.getParameter("roleId");
			    parameter.value=roleId;
			    Command_SaveAuthOper.execute();
			}
			
			//功能权限保存成功
			function Command_SaveAuthOper_onExecuteSuccess(command){
				MsgBox.showInfoMsg("操作成功！");
			}
			
			//返回
			function Button_Return_onClick(){
			    var tabName = "<%=request.getParameter("openerTabName") %>";
				returnToParentTab(tabName,false);  
			}
			
			//新增数据权限
			function RecordButton_insert_onClick(){
			  	if (!Dataset_AuthData) 
			  		return;
			   	var panel2 = $J(Panel2);
			    var roleId = panel2.tag;
			   
			    Dataset_AuthData.insertRecord();
			    Dataset_AuthData.setValue("roleId",roleId);
			    Dataset_AuthData.setValue("authType",'1');
			    Dataset_AuthData.setValue("isIncludeSubOrg",'1');
			    Dataset_AuthData.setValue("authScopeId","owner");
			    Dataset_AuthData.setValue("authScopeName","用户所属部门");
			}
			
			//数据类型选择（部门数据 or 个人数据）
			var authTypeValue = '1';	//数据类型，1为部门数据范围，2为用户数据范围
			function ListDropDown_authType_onSelect(dropdown,item,text){
				if (!Dataset_AuthData) 
					return;
			  
			  	var tmp = item.getValue();
			  
				if(tmp == '1'){
					authTypeValue = '1';
					Dataset_AuthData.setValue("authScopeId","owner");
					Dataset_AuthData.setValue("authScopeName","用户所属部门");
					Dataset_AuthData.setValue("isIncludeSubOrg","1");
					
					var lookupDropDown_DataScope = $J("LookupDropDown_DataScope");
					var path = "/jsp/framework/sys/org/orgDropdown.jsp?from=dataAuth";
					lookupDropDown_DataScope.setPath(path,true);
					lookupDropDown_DataScope.windowCaption = "选择部门数据";
				}else if(tmp == '2'){
					authTypeValue = '2';
					Dataset_AuthData.setValue("authScopeId","owner");
					Dataset_AuthData.setValue("authScopeName","本人数据");
					Dataset_AuthData.setValue("isIncludeSubOrg","0");
					  
					var lookupDropDown_DataScope = $J("LookupDropDown_DataScope");
					var path = "/jsp/framework/sys/user/userDropdown.jsp";
					lookupDropDown_DataScope.setPath(path,true);
					lookupDropDown_DataScope.windowCaption = "选择用户数据";
				}
				
			  	return true;
			}
			
			//选择数据范围之前（处理弹出页）
			function LookupDropDown_DataScope_onBeforeOpen(dropdown){
				var authType = Dataset_AuthData.getValue("authType");
				var lookupDropDown_DataScope = $J("LookupDropDown_DataScope");
				if(authType == '1'){
				     var path = "/jsp/framework/sys/org/orgDropdown.jsp?from=dataAuth";
				     lookupDropDown_DataScope.setPath(path,true);
				     lookupDropDown_DataScope.windowCaption = "选择部门数据";
				}else if(authType == '2'){
				     var path = "/jsp/framework/sys/user/userDropdown.jsp";
				     lookupDropDown_DataScope.setPath(path,true);
				     lookupDropDown_DataScope.windowCaption = "选择用户数据";
				}
			}
			
			//选择数据范围之后(处理dataset的值) 
			function LookupDropDown_DataScope_onSelect(dropdown,iframe,text){
				if (!Dataset_AuthData) 
					return;
			 
			    if(authTypeValue == '1'){//机构
			    	var ds = $J(iframe.Dataset_Org);
			    	if(ds){
				    	var record = ds.getCurrentRecord();
				    	if(typeof record != "undefined" && record != null){
				       		Dataset_AuthData.setValue("authScopeId",record.getValue("orgId"));
			    			Dataset_AuthData.setValue("authScopeName",record.getValue("orgName"));
			    			if(record.getValue("orgId") == "all_org"){//所有部门，包含下级
			    				Dataset_AuthData.setValue("isIncludeSubOrg","1");
			    			}
				    	}
					}
			    }else if(authTypeValue == '2'){//用户
			    	var ds = $J(iframe.Dataset_User);
			    	if(ds){
				    	var record = ds.getCurrentRecord();
				    	if(typeof record != "undefined" && record != null){
				       		Dataset_AuthData.setValue("authScopeId",record.getValue("userId"));
			    			Dataset_AuthData.setValue("authScopeName",record.getValue("userName"));
				    	}
					}
			    }
			}
			
			//选择所有部门时，必须包含下级
			function Grid_AuthData_onClick(){
			    var element=event.srcElement;
			    if(element.isDataCell) {
			       	var currentRecord = element.record;
			      	if(currentRecord){
			      		if(currentRecord.getValue("authScopeId") == "all_org" || currentRecord.getValue("authType") == "2" ){
			      			$J("Dataset_AuthData").getField("isIncludeSubOrg").setReadOnly(true);
			      		}else{
			      			$J("Dataset_AuthData").getField("isIncludeSubOrg").setReadOnly(false);
			      		}
			      	}
			   	}
			}
			
			//数据权限保存成功
			function Command_SaveAuthData_onExecuteSuccess(command){
				MsgBox.showInfoMsg("操作成功！");
			}
		</script>
	
	</e:View>
</html>
